<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Login;
use think\console\command\make\Model;

class Index extends Controller
{

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return view('index/index');
    }


    // /**
    //  * 后台登录页面
    //  * @return \think\response\View
    //  */
    // public function index()
    // {
    //     return view('index/login');
    // }

    /**
     * 后台登录处理
     * @return \think\response\View
     */

    public function doLogin()
    {
        $data = input('post.');
        $result = new Login();
        $checking = $result->check($data);
        return view('index/index');

    }
    //处理加载前台用户列表
    public function userlist()
    {
        $user = new Login();
        $data = $user->getUser();

        if($data){
            return view('user/index',[
                'data'=>$data,
            ]);
        }else{
            return $this->error('查询出错请稍后重试!');
        }
    }
    //处理ajax无刷新更改状态
    public function change()
    {
        $data = input('post.');
        $row = db('user')->where('id', $data['code'])->update(['status' => $data['n']]);
        if ($row){
            echo 1;
        }else{
            echo 2;
        }

    }

    public function showDetail()
    {
        $id = input('post.id');
        $user = new Login();
        $result = $user->getDetail($id);

        return json($result);

    }
}
